import { observable, action } from 'mobx';
import BaseListStore from './BaseListStore';
import * as Apis from '../apis/sellChance';
import { CrmContactStore } from './crmContactStore';
import { WeaLocaleProvider } from 'ecCom';
import * as API_MINECUSTOMER from '../apis/mineCustomer';

const getLabel = WeaLocaleProvider.getLabel;
export class ListStore extends BaseListStore {
    @observable customerId = '';
    @observable chanceDialogTile = '';
    @observable chanceDialogShow = false;
    @observable chanceDialogParams = {};
    @observable crmContactStore = new CrmContactStore();
    @observable remindInfo = {};
    @observable chanceTabDialogTile = '';
    @observable chanceTabDialogShow = false;
    @observable chanceTabDialogParams = {};

    constructor() {
      super();
      this.searchInputName = 'subject';
      // this.customerId = ;
    }

    @action
    showChanceDialog=(bool = false, obj = {}, title) => {
      this.chanceDialogShow = bool;
      this.chanceDialogParams = obj;
      this.chanceDialogTile = title;
      if (!bool) {
        this.reLoad();
      }
    }

    @action
    showChanceAddDialog=(bool = false, obj = {}) => {
      this.chanceAddDialogShow = bool;
      this.chanceAddDialogParams = obj;
    }


    @action
    showChanceTabDialog=(bool = false, obj = {}, title) => {
      this.chanceTabDialogShow = bool;
      this.chanceTabDialogParams = obj;
      this.chanceTabDialogTile = title;
      if (!bool) {
        this.reLoad();
      }
    }

    getTableData(requestParams, callBackFn) {
      requestParams.fromType = '1';
      requestParams.customerId = this.routerParams.customerId;
      this.customerId = this.routerParams.customerId;
      Apis.getChanceList(requestParams).then((data) => {
        callBackFn(data);
      });
    }

    batchDelete(selectedRowKeys) {
      const requestParams = { sellChanceIds: selectedRowKeys };
      Apis.chanceDelete(requestParams).then((data) => {
        this.reLoad();
      });
    }

    // 商机管理 -- 是否标记重要
    isMarkToImportant=(params) => {
      API_MINECUSTOMER.markImportant(params).then((data) => {
        if (data.status == 'success') {
          this.reLoad();
          return true;
        }
        message.error(getLabel(83437, '出现错误！') + data.msgcode);
      });
    }
}
